package com.example.springsecurityextraloginfield.repository.impl;

import com.example.springsecurityextraloginfield.entity.UserDAO;
import com.example.springsecurityextraloginfield.repository.UserRepository;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Collection;

@Repository(value = "userRepository")
public class UserRepositoryImpl implements UserRepository {

    private final PasswordEncoder passwordEncoder;

    public UserRepositoryImpl(PasswordEncoder passwordEncoder) {
        this.passwordEncoder = passwordEncoder;
    }

    @Override
    public UserDAO findUser(String username, String domain) {
        if (StringUtils.isBlank(username) || StringUtils.isBlank(domain)) {
            return null;
        }else{
            Collection<? extends GrantedAuthority> authorities = new ArrayList<>();
            UserDAO userDAO = new UserDAO(username,domain, passwordEncoder.encode("123456"),true,true,true,true,authorities );
            return userDAO;
        }
    }
}
